import request from '../utils/request.js'


export const login = function (user) {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: user

  })
}

export const getInfo = function () {
  return request({
    method: 'GET',
    url: 'v1_0/user/profile'
  })
}

// 关注
export const follow = userId => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: userId
    }
  })
}

// 取关
export const unfollow = userId => {
  return request({
    url: '/v1_0/user/followings/' + userId,
    method: 'DELETE'
  })
}

// eslint-disable-next-line camelcase
export const get_info = function () {
  return request({
    method: 'GET',
    url: 'v1_0/user'
  })
}

/**
 * 编辑用户信息
 * data: {
 *  name,
 *  gender,
 *  birthday
 * }
 */
export const updateUserInfo = (data) => {
  return request({
    method: 'PATCH',
    url: 'v1_0/user/profile',
    data
  })
}

/**
 * 修改用户头像
 *
 * obj： 以formData格式保存参数
 */
/**
 * 更新用户头像
 * @param {*} fd 头像
 */
export const updateUserPhoto = (obj) => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data: obj
  })
}

export const updateUserGender = (gender) => {
  return request({
    method: 'PATCH',
    url: 'v1_0/user/profile',
    data: gender
  })
}

//  时间格式化
export const formatDate = (dateTime) => {
  // console.log(date)
  // date = new Date();
  const date = new Date(dateTime) // 转换成Data();
  console.log(date)
  var y = date.getFullYear()
  console.log(y)
  var m = date.getMonth() + 1
  m = m < 10 ? '0' + m : m
  var d = date.getDate()
  d = d < 10 ? ('0' + d) : d
  return y + '-' + m + '-' + d
}
